#ifndef H_RCGD_STRUCT_H
#define H_RCGD_STRUCT_H 

/*=================================================================*/
/*                           MAIN.c                                */
/*=================================================================*/
/* time - <8> */
typedef struct time_s{

    unsigned short  YEAR;
    unsigned char   MONTH;
    unsigned char   DAY;
    unsigned char   HOUR;
    unsigned char   MINUTE;
    unsigned char   SECOND;

    unsigned char	dummy;
} time_;



/* TIME - <34> */
typedef struct TIME_S{

    time_	CUR;
    time_	UTC;
    time_	GPS;
    time_	MID;
    time_	TOUT;

    //kang char     LEAPSECOND;
	signed char     LEAPSECOND;
	signed char     LEAPSECPENDING;

    unsigned char   TIMEMODE;

    //kang char            LOCALHOUR;
    //kang char            LOCALMINUTE;
	signed char            LOCALHOUR;
    signed char            LOCALMINUTE;
	
	int				TOD_MatchCounter;
	int				TOD_MismatchCounter;
		
	//char			Valid;
	signed char		Valid;
	
	unsigned char   SYS_TIMEMODE;
    signed char     SYS_LOCALHOUR;
    signed char     SYS_LOCALMINUTE;

    long            ANTDLY;

} TIME_;


/* Position <12> */
typedef struct P_S{
    long int    LAT;
    long int    LON;
    long int    HEI;
}P_;

/*
typedef struct p_s{
	char	lat_d;
	int		lat_Do;
	int		lat_Boon;
	float	lat_Cho;
	char	lon_d;
	int		lon_Do;
	int		lon_Boon;
	float	lon_Cho;
	float	hei;
} P_DBC_;
*/

typedef struct POS_S{
	short	AveragingNo; 		/* Averaging */
    short   AveragingCounter; 	/* AveragingNo */
    short	PAveragingCounter;
    char    Survey;  			/* SURVEY_ON, SURVEY_PAUSE, SURVEY_OFF */
    char	PositionMode;		/* Position hold  on off */
    P_  CURRENT;
    P_  AVERAGE;
    P_  LASTHELD;
    P_	ACC;		/* Position */
    P_	PAVERAGE;
}POS_;


/* Position Hold Position */
#define disablePHM  0
#define enablePHM   1
#define enablePHP   2

typedef struct PHP_S{
	char    Counter;
	char	TryCounter;
    char    STEP;
    char    match;
    P_      POSITION;
} PHP_;


/* Position averaging */
#define     Latitude    0
#define     Longitude   1
#define     Height      2

typedef struct CPOS_S {
    P_      Pos[10];
    char    Count;
} CPOS_;

/* TRACK */
typedef struct SAT_S{
        char        ID;
        char        SS;
        char		MODE;
        char		STATUS;
} SAT_;

typedef struct{
        unsigned char  	ID;
        unsigned char  	EL;
        unsigned short 	AZ;
        unsigned char	HEALTH;
} VIS_SAT_;


typedef struct TS_S{
    short        	DOP;
    unsigned char   DOPTYPE;
    unsigned char   VISIBLE;
    unsigned char   TRACKED;
    unsigned char   STATUS;
    SAT_            SAT[16];      /* 32 */
    VIS_SAT_		VIS_SAT[16]; /* 72 */
    char			satmonitor[16];
    unsigned char	MASK;
    unsigned int 	BINSAT;
    int				PRN_USED[16];
} TS_;


typedef struct {

	unsigned short 	LIMIT;
	unsigned short	T_LIMIT;
	char 			FLAG;
	char 			CTRLMODE;
	char 			PULSE;
	char 			PULSESYNC;
	char 			SOL_STATUS;
	char 			STATUS;
	unsigned short 	ACCURACY;
	signed char		SAWTOOTH;

	char			SAT[8];
	unsigned int	SATTIME[8];
} TRAIM_;

/* Engine Board */
typedef struct EB_S{

    char	MODEL[16];
    char	SERIAL[16];
    char	SWVER[12];
    char	SWREV[12];
    char	SWDATE[12];

	char	TASK;
	char	set_step;
	char	almanac_step;
	char	DIAG;
	int		IntervalCounter;

	char	ID;
	char	SUBID;
    char    SELFTEST;
    char    PSDM;
    char	SATSTATUS;
    char    PHM;
    char	LEAPSECOND;
    char    LEAPSECPENDING;
    char    LOCKMODE;   /* Locked, Unlocked */
    char    ANTENNA, PrevANTENNA;

	char	LockCheck;

	time_	TIME;
    char    LOCALHOUR;
    char    LOCALMINUTE;
    long    ANTDLY;
    char	TIMEMODE;
    char	STATUS;

	char	rxflag;
	int		RxCounter;
	int 	RxCheckCounter;
	PHP_	PHP;

    char     AntennaFaultTable[10];
	int		antenna_fault_counter;

    char    PHP_Enable;
    char    PHM_Disable;
	char	settodefault;
	char	EB_Default;

	int bRcvZDA;				//global -> struct EB change
	int zero_tracking;		//global -> struct EB change
	int prevTODSec;			//global -> struct EB change
	int once_receiver_detect;	//global -> struct EB change
	int model_cnt;				//global -> struct EB change
	int print_Flag;
	int command_Flag;

	int		UnlockedCounter;
	int		UnlockedDelayCounter;
	int		LockedCounter;
	int 	LockedCounter_1;	//#120807# sewon
	int		UnlockedCounter_1;	//#120807# sewon
	TRAIM_	TRAIM;
	char *model_name;

} EB_;
extern EB_	EB;


/* Operation */
typedef struct OP_S{
    char    OPMODE;     /*  OPMODE_POWERUP->
                            OPMODE_WARMUP->
                            OPMODE_OPERATION */
    char    LOCKMODE;   /*  Locked,
                            Holdover,
                            Unlocked,
                            Recovery */
    int    STATUS;     /*  STATUS_Active,
                            STATUS_Standby,
                            STATUS_Block,
                            STATUS_Unlock */
	char	SELFTEST;	/* selftest */

	char	CTRLMODE;	/* 	CTRL_LOCKEDtoGPS
							CTRL_LOCKEDtoMASTER  */

	char	RUN_MODE;	/* Y2K */
	char	DETAIL_MODE;	/* DETAIL Update�?UN */
} OP_;

/* Port configuration */
typedef struct PORT_S{
    int		Timer;
    char	COMMAND_SET;
    char    MODE;
    char    PROMPT;
	char	Print;
	char	Odtcmd;
} PORT_;

typedef struct IO_S{
    PORT_   CTRL_PORT;
    PORT_   COMMON_PORT;
} IO_;

#define DIFF_TABLE_SIZE	30


typedef struct {
	char	STATUS;
	char	LOCKMODE;
	int		enable_counter;
	int		disable_counter;

	int raw_digit_all;
	int prev_raw_digit_all;
	int raw_digit_all_2;
	int	raw_count_all;
	int raw_count_diff;

	int		skip_counter;

	int		IntervalCounter;

	int	diff_table_counter;
	int diff_table_index;
	int diff_table[DIFF_TABLE_SIZE];
	char ACCU_STATUS;
	int diff_table_sum;
	
	
	int invalid_check_counter;
	int invalid_counter;
	char invalid_flag;
	char IsE1In;
	
	float moving_average;
	
	float Accuracy;
	float Jitter_Boundary;

} E1_;

/*----------------------------------------------*/
/*      Main Structure                          */
/*----------------------------------------------*/
typedef struct SYS_S{
    char    ID;         /* Module A or Module B */
    char	MODE;		/* BTS or BSC */
    TIME_   TIME;		/* 16 */
    POS_    POSITION;	/* 40 */ 	//OEMV2 Data (TDOA)
    TS_     TRACK;		/* 22 */
    EB_     EB;			/* 6 */

    POS_    POSITION2;	/* 40 */ 	//OEMV1 Data (TDOA)
    TS_     TRACK2;		/* 22 */
    EB_     EB2;			/* 6 */

    OP_     OPERATION;	/* 4 */
    IO_     IO;			/* 4 */

    E1_		E1;
    E1_		E2;
} SYS_;
extern SYS_	SYSTEM;


/*----------------------------------------------*/
/*      EVENT                                   */
/*----------------------------------------------*/
typedef struct EVENT_S{
    char    OnePPS1;
	char    OnePPS2;
    char    SCC1;
    char	SCC1_TX;
    char 	SCC2;
    char	SCC3;
    char	SCC3_TX;
    char 	SCC4;
    char	SCC5;
    char	SCC6;
    char    TIMER1;
    char    TIMER2;
    char    PLL;
	char	CALCULATION;

} EVENT_;




/* general counters */
typedef struct GC_S{
    int Second;
    int Hour;
    int Day;
    int ACCsecond;
    int	RunningTime;
} GC_;
extern GC_     GC;

/*----------------------------------------------*/
/*    for   RealTime Job                        */
/*----------------------------------------------*/
typedef struct RT_S{
	char T10ms;
	char T100ms;
	char C10ms;
	char C100ms;
	char C10msLED;
	char T4ms;
	char C4ms;
	char T500ms;
	char C500ms;
	char T1000ms;
}RT_;



typedef struct USER_S{
    char    MANUAL_HOLDOVER;
    char    MANUAL_CONTROL;
    char	MANUAL_SIG_ON;
    float	R;
    float   Q1,Q2,Q3;
} USER_;
extern USER_   USER;


#endif
